package com.ljs.account.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljs.account.Service.AccountService;
import com.ljs.account.entity.AccountVo;
import com.ljs.account.entity.Student;
import com.ljs.account.mapper.StudentMapper;
import com.ljs.account.util.JsonResult;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.apache.ibatis.reflection.wrapper.BaseWrapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class StudentController {
    @Resource
    StudentMapper studentMapper;
    @Resource
    AccountService accountService;
    @RequestMapping("/sel")
    public List<Student> sel(){
        JsonResult jsonResult=new JsonResult();
      List<Student>  studentList1=studentMapper.selectList(null);//不加条件
        //JAVA8
        int count=studentMapper.selectCount(null);
        studentList1.stream().forEach(student -> {
            System.out.println(student);
            System.out.println("数量是"+count);
        });
        //加分页
        Page page=new Page(2,2);
        List<Student>  studentList2=studentMapper.selectPage(page,null).getRecords();//分页
        //加条件
        QueryWrapper queryWrapper1=new QueryWrapper();
        queryWrapper1.like("name","刘");
        List <Student> studentList3=studentMapper.selectList(queryWrapper1);
        studentList3.stream().forEach(Student ->{
            System.out.println("含有刘的是"+Student);
        });
        QueryWrapper queryWrapper2=new QueryWrapper();
        //queryWrapper2.inSql("id","select id from student where id>2");
        queryWrapper2.select("sum(age)").gt("id",2);//查询总数
        //queryWrapper2.gt("id",2);//大于5 ge：greater
        queryWrapper2.lt("id",5);//小于5 less then
        //queryWrapper2.groupBy("id");
        List <Student> studentList4=studentMapper.selectList(queryWrapper2);
        studentList4.stream().forEach(Student ->{
            System.out.println("id大于2的小于5的"+Student);
        });
        jsonResult.setData(studentList2);
        return studentList1;
    }
    @RequestMapping("/selall")
    public     List<AccountVo> selAll(){

    List<AccountVo>  accountVos=   accountService.selaccountvo();
        accountVos.stream().forEach(AccountVo ->{
            System.out.println("多表关联查询"+AccountVo);
        });

        return  accountVos;
    }
}
